package br.ucb.gui;

import br.ucb.services.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JOptionPane;

public class OpenCadastrarAction implements ActionListener {
	private Tela1 tela;

	public OpenCadastrarAction(Tela1 tela) {
		setTela(tela);
	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == getTela().getJbConteudo()) {
			try {
				gerenciaCadastraConteudo();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (ClassNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} else {
			if (e.getSource() == getTela().getJbConceito()) {
				try {
					gerenciaCadastraConceito();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ClassNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			} else {
				if (e.getSource() == getTela().getJbDisciplina()) {
					gerenciaCadastraDisciplina();
				}else{
					if(e.getSource() == getTela().getJbGerar()){
						try {
							Acoes a =new Acoes();
							a.setVisible(true);
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						} catch (ClassNotFoundException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
				}
			}

		}
	}

	private void gerenciaCadastraDisciplina() {
		getTela().getJpPrincipal().removeAll();
		new DisciplinaGUI(getTela());
		getTela().getJpPrincipal().updateUI();
	}

	private void gerenciaCadastraConceito() throws SQLException, ClassNotFoundException {
		getTela().getJpPrincipal().removeAll();
		new ConceitoGUI(getTela());
		getTela().getJpPrincipal().updateUI();
	}

	private void gerenciaCadastraConteudo() throws SQLException, ClassNotFoundException {
		getTela().getJpPrincipal().removeAll();		
		new ConteudoGUI(getTela());
		getTela().getJpPrincipal().updateUI();
	}

	

	// Getters and Setters
	public Tela1 getTela() {
		return tela;
	}

	public void setTela(Tela1 tela) {
		this.tela = tela;
	}
}
